package com.shuai.model.loginInfo;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.shuai.model.po.SysPermission;
import com.shuai.model.po.SysRole;
import lombok.*;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

/**
 * 登录用户详细信息
 *
 * @author shuai
 * @since 2022
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class UserDetailInfo implements UserDetails {

    /**
     * 用户ID
     */
    @JsonSerialize(using = ToStringSerializer.class)
    private String id;

    /**
     * 用户账号
     */
    private String username;

    /**
     * 用户密码
     */
    private String password;

    /**
     * 用户名称
     */
    private String realName;

    /**
     * 用户头像
     */
    private String avatar;

    /**
     * 用户拥有的权限
     */
    private Collection<? extends GrantedAuthority> authorities;

    /**
     * 用户拥有的角色
     */
    private List<String> roles;

    /**
     * 用户拥有的菜单
     */
    private List<String> menus;

    /**
     * 用户拥有的权限
     */
    private List<String> permissions;


    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}